home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / System7 tools / Frontier / Frontier SDK 2.1 / Toolkits / Applet Toolkit / applettextedit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-11  |  14.9 KB  |  797 lines  |  [TEXT/KAHL]

  1.  
  2. /*© Copyright 1988-1992 UserLand Software, Inc.  All Rights Reserved.*/
  3.  
  4.  
  5. #include "appletmemory.h"
  6. #include "appletfont.h"
  7. #include "appletstrings.h"
  8. #include "appletquickdraw.h"
  9. #include "applettextedit.h"
  10.  
  11.  
  12.  
  13. typedef struct tyscrolldata {
  14.     
  15.     Rect origdestrect;
  16.     
  17.     short origlen;
  18.     } tyscrolldata;
  19.     
  20. tyscrolldata scrolldata;
  21.  
  22.  
  23.  
  24.  
  25. static boolean getmacbuffer (hdleditrecord hbuffer, TEHandle *macbuffer) {
  26.  
  27.     if (hbuffer == nil)
  28.         return (false);
  29.         
  30.     *macbuffer = (**hbuffer).macbuffer;
  31.     
  32.     return (*macbuffer != nil);
  33.     } /*getmacbuffer*/
  34.     
  35.  
  36. static void editprescroll (hdleditrecord hbuffer) {
  37.  
  38.     TEHandle macbuffer;
  39.     
  40.     if (!getmacbuffer (hbuffer, &macbuffer))
  41.         return;
  42.  
  43.     scrolldata.origdestrect = (**macbuffer).destRect;
  44.     
  45.     scrolldata.origlen = (**macbuffer).teLength;
  46.     } /*editprescroll*/
  47.     
  48.     
  49. static void editsetscrollvalues (hdleditrecord hbuffer) {
  50.  
  51.     TEHandle macbuffer;
  52.     Rect destrect, viewrect;
  53.     boolean flscrolled;
  54.     
  55.     if (!getmacbuffer (hbuffer, &macbuffer))
  56.         return;
  57.     
  58.     flscrolled = scrolldata.origlen != (**macbuffer).teLength;
  59.     
  60.     if (!flscrolled)
  61.         flscrolled = !equalrects (scrolldata.origdestrect, (**macbuffer).destRect);
  62.         
  63.     (**hbuffer).flscrolled = flscrolled;
  64.     
  65.     destrect = (**macbuffer).destRect;
  66.     
  67.     viewrect = (**macbuffer).viewRect;
  68.     
  69.     (**hbuffer).vertcurrent = viewrect.top - destrect.top;
  70.     
  71.     (**hbuffer).horizcurrent = viewrect.left - destrect.left;
  72.     } /*editsetscrollvalues*/
  73.     
  74.     
  75. static short getTEjustification (tyjustification justification) {
  76.     
  77.     switch (justification) {
  78.         
  79.         case leftjustified:
  80.             return (teJustLeft);
  81.             
  82.         case centerjustified:
  83.             return (teJustCenter);
  84.             
  85.         case rightjustified:
  86.             return (teJustRight);
  87.         } /*switch*/
  88.  
  89.     return (teJustLeft);
  90.     } /*getTEjustification*/
  91.     
  92.  
  93. boolean editnewbuffer (Rect r, boolean flwordwrap, bigstring bs, hdleditrecord *hrecord) {
  94.     
  95.     register hdleditrecord h;
  96.     register TEHandle macbuffer;
  97.     
  98.     if (!newclearhandle (longsizeof (tyeditrecord), (Handle *) hrecord))
  99.         return (false);
  100.         
  101.     h = *hrecord; /*copy into register*/
  102.     
  103.     InsetRect (&r, texthorizinset, textvertinset);
  104.         
  105.     macbuffer = TENew (&r, &r);
  106.     
  107.     if (macbuffer == nil) { /*memory error*/
  108.         
  109.         disposehandle ((Handle) h);
  110.         
  111.         *hrecord = nil;
  112.         
  113.         return (false);
  114.         }
  115.         
  116.     if (flwordwrap)
  117.         (**macbuffer).crOnly = 1;
  118.     else
  119.         (**macbuffer).crOnly = -1;
  120.  
  121.     TESetText (&bs [1], (long) stringlength (bs), macbuffer);
  122.     
  123.     TEActivate (macbuffer);
  124.     
  125.     (**h).macbuffer = macbuffer;
  126.     
  127.     return (true);
  128.     } /*editnewbuffer*/
  129.     
  130.     
  131. void editupdate (hdleditrecord hbuffer) {
  132.     
  133.     TEHandle macbuffer;
  134.     Rect r;
  135.     
  136.     if (!getmacbuffer (hbuffer, &macbuffer))
  137.         return;
  138.         
  139.     r = (**macbuffer).viewRect;
  140.     
  141.     TEUpdate (&r, macbuffer);
  142.     } /*editupdate*/
  143.     
  144.     
  145. void editupdateport (hdleditrecord hbuffer, Rect rport, WindowPtr w) {
  146.     
  147.     /*
  148.     8/26/92 DW: update the TE handle, but do it in a port different from the
  149.     one it lives inside of. need this to support printing in MinApp.
  150.     
  151.     9/3/92 DW: add "rport" parameter, to allow the caller to determine the
  152.     temporary viewRect for the TE buffer.
  153.     */
  154.     
  155.     TEHandle macbuffer;
  156.     Rect oldview, olddest;
  157.     WindowPtr oldport;
  158.     
  159.     if (!getmacbuffer (hbuffer, &macbuffer))
  160.         return;
  161.         
  162.     oldview = (**macbuffer).viewRect; 
  163.     
  164.     olddest = (**macbuffer).destRect; 
  165.     
  166.     oldport = (**macbuffer).inPort;
  167.     
  168.     (**macbuffer).viewRect = rport;
  169.     
  170.     (**macbuffer).destRect = rport;
  171.     
  172.     (**macbuffer).inPort = w;
  173.     
  174.     TEUpdate (&rport, macbuffer);
  175.     
  176.     (**macbuffer).viewRect = oldview;
  177.     
  178.     (**macbuffer).destRect = olddest;
  179.     
  180.     (**macbuffer).inPort = oldport;
  181.     } /*editupdateport*/
  182.     
  183.     
  184. void editactivate (hdleditrecord hbuffer, boolean flactive) {
  185.     
  186.     TEHandle macbuffer;
  187.     
  188.     if (!getmacbuffer (hbuffer, &macbuffer))
  189.         return;
  190.         
  191.     if (flactive)
  192.         TEActivate (macbuffer);
  193.     else
  194.         TEDeactivate (macbuffer);
  195.     } /*editupdate*/
  196.     
  197.     
  198. void editsetrect (hdleditrecord hbuffer, Rect r) {
  199.  
  200.     TEHandle macbuffer;
  201.  
  202.     if (!getmacbuffer (hbuffer, &macbuffer))
  203.         return;
  204.         
  205.     InsetRect (&r, texthorizinset, textvertinset);
  206.             
  207.     (**macbuffer).viewRect = r;
  208.     
  209.     if (!(**hbuffer).flwindowbased)
  210.         (**macbuffer).destRect = r;
  211.     
  212.     TECalText (macbuffer);
  213.     
  214.     /*editupdate (hbuffer);*/
  215.     } /*editsetrect*/
  216.     
  217.     
  218. void editsetfont (hdleditrecord hbuffer, short fontnum, short fontsize) {
  219.  
  220.     TEHandle macbuffer;
  221.  
  222.     if (!getmacbuffer (hbuffer, &macbuffer))
  223.         return;
  224.         
  225.     editprescroll (hbuffer);
  226.     
  227.     (**macbuffer).txFont = fontnum;
  228.     
  229.     (**macbuffer).txSize = fontsize;
  230.     
  231.     pushstyle (fontnum, fontsize, (**macbuffer).txFace);
  232.     
  233.     (**macbuffer).fontAscent = globalfontinfo.ascent;
  234.     
  235.     (**macbuffer).lineHeight = globalfontinfo.ascent + globalfontinfo.descent + globalfontinfo.leading;
  236.     
  237.     popstyle ();
  238.         
  239.     TECalText (macbuffer);
  240.     
  241.     editsetscrollvalues (hbuffer);
  242.     
  243.     (**hbuffer).flscrolled = true;
  244.     } /*editsetfont*/
  245.     
  246.     
  247. void editautoscroll (hdleditrecord hbuffer) {
  248.  
  249.     TEHandle macbuffer;
  250.  
  251.     if (!getmacbuffer (hbuffer, &macbuffer))
  252.         return;
  253.         
  254.     TEAutoView (true, macbuffer);
  255.     } /*editautoscroll*/
  256.     
  257.     
  258. void editsetwordwrap (hdleditrecord hbuffer, boolean fl) {
  259.     
  260.     TEHandle macbuffer;
  261.     register short cronly;
  262.  
  263.     if (!getmacbuffer (hbuffer, &macbuffer))
  264.         return;
  265.     
  266.     if (fl)
  267.         cronly = 1; /*word-wrap on*/
  268.     else
  269.         cronly = -1; /*no word-wrap*/
  270.         
  271.     (**macbuffer).crOnly = cronly; 
  272.     } /*editsetwordwrap*/
  273.     
  274.  
  275. void editdispose (hdleditrecord hbuffer) {
  276.     
  277.     TEHandle macbuffer;
  278.     
  279.     if (!getmacbuffer (hbuffer, &macbuffer))
  280.         return;
  281.     
  282.     TEDeactivate (macbuffer); /*remove the caret cursor, or unhighlight selection*/
  283.     
  284.     TEDispose (macbuffer);
  285.         
  286.     disposehandle ((Handle) hbuffer);
  287.     } /*editdispose*/
  288.  
  289.  
  290. void editdrawtext (bigstring bs, Rect r, tyjustification justification) {
  291.     
  292.     InsetRect (&r, texthorizinset, textvertinset);
  293.     
  294.     TextBox (&bs [1], stringlength (bs), &r, getTEjustification (justification));
  295.     } /*editdrawtext*/
  296.     
  297.  
  298. void editdrawtexthandle (Handle htext, Rect r, tyjustification justification) {
  299.     
  300.     if (htext == nil)
  301.         return;
  302.     
  303.     InsetRect (&r, texthorizinset, textvertinset);
  304.     
  305.     TextBox (*htext, GetHandleSize (htext), &r, getTEjustification (justification));
  306.     } /*editdrawtexthandle*/
  307.     
  308.  
  309. void editidle (hdleditrecord hbuffer) {
  310.     
  311.     TEHandle macbuffer;
  312.     
  313.     if (!getmacbuffer (hbuffer, &macbuffer))
  314.         return;
  315.     
  316.     TEIdle (macbuffer);
  317.     } /*editidle*/
  318.     
  319.     
  320. void editcut (hdleditrecord hbuffer) {
  321.     
  322.     TEHandle macbuffer;
  323.     
  324.     if (!getmacbuffer (hbuffer, &macbuffer))
  325.         return;
  326.  
  327.     editprescroll (hbuffer);
  328.     
  329.     TECut (macbuffer);
  330.     
  331.     editsetscrollvalues (hbuffer);
  332.     } /*editcut*/
  333.  
  334.  
  335. void editcopy (hdleditrecord hbuffer) {
  336.     
  337.     TEHandle macbuffer;
  338.     
  339.     if (!getmacbuffer (hbuffer, &macbuffer))
  340.         return;
  341.  
  342.     TECopy (macbuffer);
  343.     } /*editcopy*/
  344.  
  345.  
  346. void editpaste (hdleditrecord hbuffer) {
  347.     
  348.     TEHandle macbuffer;
  349.     
  350.     if (!getmacbuffer (hbuffer, &macbuffer))
  351.         return;
  352.  
  353.     editprescroll (hbuffer);
  354.     
  355.     TEPaste (macbuffer);
  356.     
  357.     editsetscrollvalues (hbuffer);
  358.     } /*editpaste*/
  359.     
  360.     
  361. boolean editgettext (hbuffer, bs) hdleditrecord hbuffer; bigstring bs; {
  362.  
  363.     TEHandle macbuffer;
  364.     register int len;
  365.     
  366.     setstringlength (bs, 0);
  367.     
  368.     if (!getmacbuffer (hbuffer, &macbuffer))
  369.         return (false);
  370.  
  371.     len = (**macbuffer).teLength;
  372.     
  373.     setstringlength (bs, len);
  374.             
  375.     moveleft (*(**macbuffer).hText, &bs [1], (long) len); 
  376.     
  377.     return (true);
  378.     } /*editgettext*/
  379.  
  380.  
  381. void editkeystroke (char chkb, hdleditrecord hbuffer) {
  382.  
  383.     TEHandle macbuffer;
  384.     
  385.     if (!getmacbuffer (hbuffer, &macbuffer))
  386.         return;
  387.  
  388.     editprescroll (hbuffer);
  389.     
  390.     TEKey (chkb, macbuffer);
  391.     
  392.     editsetscrollvalues (hbuffer);
  393.     } /*editkeystroke*/
  394.     
  395.     
  396. void editclick (Point pt, boolean flshiftkey, hdleditrecord hbuffer) {
  397.  
  398.     TEHandle macbuffer;
  399.     
  400.     if (!getmacbuffer (hbuffer, &macbuffer))
  401.         return;
  402.         
  403.     editprescroll (hbuffer);
  404.  
  405.     pushclip ((**macbuffer).viewRect);
  406.     
  407.     TEClick (pt, flshiftkey, macbuffer);
  408.     
  409.     popclip ();
  410.     
  411.     editsetscrollvalues (hbuffer);
  412.     } /*editclick*/
  413.     
  414.  
  415. boolean editsetselection (hdleditrecord hbuffer, short selstart, short selend) {
  416.  
  417.     TEHandle macbuffer;
  418.     
  419.     if (!getmacbuffer (hbuffer, &macbuffer))
  420.         return (false);
  421.         
  422.     editprescroll (hbuffer);
  423.  
  424.     TESetSelect (selstart, selend, macbuffer);
  425.     
  426.     editsetscrollvalues (hbuffer);
  427.         
  428.     return (true);
  429.     } /*editgetselection*/
  430.  
  431.  
  432. void editselectall (hdleditrecord hbuffer) {
  433.     
  434.     editsetselection (hbuffer, 0, 32767);
  435.     } /*editselectall*/
  436.     
  437.  
  438. boolean editgetselection (hdleditrecord hbuffer, short *selstart, short *selend) {
  439.  
  440.     TEHandle macbuffer;
  441.     
  442.     if (!getmacbuffer (hbuffer, &macbuffer))
  443.         return (false);
  444.         
  445.     *selstart = (**macbuffer).selStart;
  446.     
  447.     *selend = (**macbuffer).selEnd;
  448.     
  449.     return (true);
  450.     } /*editgetselection*/
  451.  
  452.  
  453. boolean editpointinrect (Point pt, hdleditrecord hbuffer) {
  454.  
  455.     TEHandle macbuffer;
  456.     
  457.     if (!getmacbuffer (hbuffer, &macbuffer))
  458.         return (false);
  459.  
  460.     return (PtInRect (pt, &(**macbuffer).viewRect));
  461.     } /*editpointinrect*/
  462.     
  463.  
  464. boolean editreplace (bigstring bs, hdleditrecord hbuffer) {
  465.  
  466.     TEHandle macbuffer;
  467.     
  468.     if (!getmacbuffer (hbuffer, &macbuffer))
  469.         return (false);
  470.     
  471.     editprescroll (hbuffer);
  472.     
  473.     if ((**macbuffer).selStart != (**macbuffer).selEnd)
  474.         TEDelete (macbuffer);
  475.     
  476.     TEInsert (&bs [1], stringlength (bs), macbuffer);
  477.     
  478.     editsetscrollvalues (hbuffer);
  479.     
  480.     return (true); /*TE gives no way to return an error*/
  481.     } /*editreplace*/
  482.     
  483.     
  484. void editsetjustification (tyjustification justification, hdleditrecord hbuffer) {
  485.  
  486.     TEHandle macbuffer;
  487.     
  488.     if (!getmacbuffer (hbuffer, &macbuffer))
  489.         return;
  490.     
  491.     TESetJust (getTEjustification (justification), macbuffer);
  492.     } /*editsetjustification*/
  493.  
  494.  
  495. void editgetsize (Handle htext, short *height, short *width) {
  496.     
  497.     /*
  498.     return the size of a rectangle that could contain the indicated string
  499.     observing the defaults for inset both vertically and horizontally, and 
  500.     a minimum width for text display.
  501.     
  502.     assumes that the font/size/style info are correct in globalfontinfo.
  503.     
  504.     8/8/92 DW: upgrade to not use a bigstring to hold the text to be measured.
  505.     we were encountering lines that were longer than 255 chars.
  506.     */
  507.     
  508.     long textlength;
  509.     long i;
  510.     short ctlines = 1;
  511.     short maxwidth = 0;
  512.     short vertpixels;
  513.     short ixlinestart = 0, linelength = 0;
  514.     
  515.     textlength = GetHandleSize (htext);
  516.         
  517.     for (i = 0; i <= textlength; i++) {
  518.         
  519.         char ch = (*htext) [i];
  520.             
  521.         if ((ch == chreturn) || (i == textlength)) {
  522.             
  523.             short w;
  524.             
  525.             w = TextWidth (*htext, ixlinestart, linelength);
  526.             
  527.             if (w > maxwidth)
  528.                 maxwidth = w;
  529.             
  530.             if (ch == chreturn)
  531.                 ctlines++;
  532.             
  533.             ixlinestart += linelength + 1;
  534.             
  535.             linelength = 0;
  536.             }
  537.         else
  538.             linelength++;
  539.         } /*for*/
  540.  
  541.     maxwidth = max (maxwidth, mintextwidth);
  542.     
  543.     maxwidth += 2 * texthorizinset;
  544.     
  545.     maxwidth++; /*ask for one extra pixel, work around TE display anomaly*/
  546.     
  547.     *width = maxwidth;
  548.     
  549.     vertpixels = ctlines * (globalfontinfo.ascent + globalfontinfo.descent + globalfontinfo.leading);
  550.     
  551.     *height = vertpixels + (2 * textvertinset);
  552.     } /*editgetsize*/
  553.     
  554.     
  555. void editgetbuffersize (hdleditrecord hbuffer, short *height, short *width) {
  556.     
  557.     /*
  558.     8/8/92 DW for Snuffy: can't rely on the value for height returned by editgetsize, 
  559.     since it doesn't take word-wrapping into account.
  560.     */
  561.     
  562.     TEHandle macbuffer;
  563.     char lastchar;
  564.     
  565.     if (!getmacbuffer (hbuffer, &macbuffer))
  566.         return;
  567.     
  568.     editgetsize ((**macbuffer).hText, height, width);
  569.     
  570.     if ((**hbuffer).flwindowbased) {
  571.     
  572.         *height = ((**macbuffer).nLines * (**macbuffer).lineHeight) + globalfontinfo.descent;
  573.         
  574.         lastchar = (*(**macbuffer).hText) [(**macbuffer).teLength - 1];
  575.         
  576.         if (lastchar != chreturn) /*a quirk of TE*/
  577.             *height += (**macbuffer).lineHeight;
  578.         
  579.         if ((**macbuffer).crOnly == 1) { /*word-wrapping turned on*/
  580.         
  581.             Rect r = (**macbuffer).destRect;
  582.         
  583.             *width = r.right - r.left;
  584.             }
  585.         }
  586.         
  587.     *width += 2 * texthorizinset;
  588.     
  589.     *height += 2 * textvertinset;
  590.     } /*editgetbuffersize*/
  591.     
  592.     
  593. boolean editgettexthandle (hdleditrecord hbuffer, Handle *htext) {
  594.     
  595.     /*
  596.     return the text handle from the edit buffer. do not dispose the handle or
  597.     alter the length of the text.
  598.     */
  599.  
  600.     TEHandle macbuffer;
  601.     
  602.     if (!getmacbuffer (hbuffer, &macbuffer))
  603.         return (false);
  604.         
  605.     *htext = (**macbuffer).hText;
  606.     
  607.     return (true);
  608.     } /*editgettexthandle*/
  609.  
  610.  
  611. boolean editnewbufferfromhandle (Rect r, boolean flwordwrap, Handle htext, hdleditrecord *hrecord) {
  612.     
  613.     register hdleditrecord h;
  614.     register TEHandle macbuffer;
  615.     
  616.     if (!newclearhandle (longsizeof (tyeditrecord), (Handle *) hrecord))
  617.         return (false);
  618.         
  619.     h = *hrecord; /*copy into register*/
  620.     
  621.     InsetRect (&r, texthorizinset, textvertinset);
  622.         
  623.     macbuffer = TENew (&r, &r);
  624.     
  625.     if (macbuffer == nil) { /*memory error*/
  626.         
  627.         disposehandle ((Handle) h);
  628.         
  629.         *hrecord = nil;
  630.         
  631.         return (false);
  632.         }
  633.         
  634.     if (flwordwrap)
  635.         (**macbuffer).crOnly = 1;
  636.     else
  637.         (**macbuffer).crOnly = -1;
  638.  
  639.     lockhandle (htext);
  640.     
  641.     TESetText (*htext, GetHandleSize (htext), macbuffer);
  642.     
  643.     unlockhandle (htext);
  644.     
  645.     TEActivate (macbuffer);
  646.     
  647.     (**h).macbuffer = macbuffer;
  648.     
  649.     return (true);
  650.     } /*editnewbufferfromhandle*/
  651.     
  652.     
  653. boolean editsettexthandle (hdleditrecord hrecord, Handle htext) {
  654.  
  655.     TEHandle macbuffer;
  656.     
  657.     if (!getmacbuffer (hrecord, &macbuffer))
  658.         return (false);
  659.         
  660.     lockhandle (htext);
  661.     
  662.     TESetText (*htext, GetHandleSize (htext), macbuffer);
  663.     
  664.     unlockhandle (htext);
  665.     
  666.     return (true);
  667.     } /*editsettexthandle*/
  668.     
  669.     
  670. boolean editgettexthandlecopy (hdleditrecord hbuffer, Handle *htext) {
  671.     
  672.     /*
  673.     caller must dispose of the handle we allocate.
  674.     
  675.     7/8/92 DW: if there is no text, return true with htext == nil.
  676.     */
  677.  
  678.     TEHandle macbuffer;
  679.     Handle h;
  680.     
  681.     if (!getmacbuffer (hbuffer, &macbuffer))
  682.         return (false);
  683.     
  684.     h = (**macbuffer).hText;
  685.     
  686.     if (GetHandleSize (h) == 0) {
  687.     
  688.         *htext = nil;
  689.         
  690.         return (true);
  691.         }
  692.     
  693.     return (copyhandle (h, htext));
  694.     } /*editgettexthandlecopy*/
  695.  
  696.  
  697. boolean edithaveselection (hdleditrecord hbuffer) {
  698.  
  699.     TEHandle macbuffer;
  700.     
  701.     if (!getmacbuffer (hbuffer, &macbuffer))
  702.         return (false);
  703.     
  704.     return ((**macbuffer).selStart != (**macbuffer).selEnd);
  705.     } /*edithaveselection*/
  706.     
  707.     
  708. boolean editscroll (hdleditrecord hbuffer, short dh, short dv) {
  709.  
  710.     TEHandle macbuffer;
  711.     
  712.     if (!getmacbuffer (hbuffer, &macbuffer))
  713.         return (false);
  714.         
  715.     editprescroll (hbuffer);
  716.     
  717.     TEScroll (dh, dv, macbuffer);
  718.     
  719.     editsetscrollvalues (hbuffer);
  720.     
  721.     return (true);
  722.     } /*edithaveselection*/
  723.     
  724.     
  725. void editscrollto (hdleditrecord hbuffer, short h, short v) {
  726.         
  727.     TEHandle macbuffer;
  728.     
  729.     if (!getmacbuffer (hbuffer, &macbuffer))
  730.         return;
  731.     
  732.     editsetscrollvalues (hbuffer);
  733.     
  734.     editscroll (hbuffer, (**hbuffer).horizcurrent - h, (**hbuffer).vertcurrent - v);
  735.     } /*editscrollto*/
  736.  
  737.  
  738. boolean editreplacehandle (Handle htext, hdleditrecord hbuffer) {
  739.  
  740.     TEHandle macbuffer;
  741.     
  742.     if (!getmacbuffer (hbuffer, &macbuffer))
  743.         return (false);
  744.     
  745.     editprescroll (hbuffer);
  746.     
  747.     if ((**macbuffer).selStart != (**macbuffer).selEnd)
  748.         TEDelete (macbuffer);
  749.         
  750.     lockhandle (htext);
  751.     
  752.     TEInsert (*htext, GetHandleSize (htext), macbuffer);
  753.     
  754.     unlockhandle (htext);
  755.     
  756.     editsetscrollvalues (hbuffer);
  757.     
  758.     return (true); /*TE gives no way to return an error*/
  759.     } /*editreplacehandle*/
  760.     
  761.     
  762. boolean editgetselectedtexthandle (hdleditrecord hbuffer, Handle *htext) {
  763.  
  764.     TEHandle macbuffer;
  765.     short selstart, selend;
  766.     short lensel;
  767.     Handle h;
  768.     boolean fl;
  769.     
  770.     if (!getmacbuffer (hbuffer, &macbuffer))
  771.         return (false);
  772.         
  773.     selstart = (**macbuffer).selStart;
  774.     
  775.     selend = (**macbuffer).selEnd;
  776.     
  777.     lensel = selend - selstart;
  778.     
  779.     if (lensel < 0)
  780.         lensel = 0;
  781.         
  782.     h = (**macbuffer).hText;
  783.     
  784.     lockhandle (h);
  785.     
  786.     fl = newfilledhandle (&((*h) [selstart]), (long) lensel, htext);
  787.     
  788.     unlockhandle (h);
  789.     
  790.     return (fl);
  791.     } /*editgetselectedtexthandle*/
  792.  
  793.  
  794.  
  795.     
  796.     
  797.